package com.idudiao.sc.neo4j.repository;

import com.idudiao.sc.neo4j.model.relationship.Transaction;
import org.neo4j.ogm.model.Result;
import org.springframework.data.neo4j.annotation.Depth;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;

/**
 * @author songyinyin
 * @since 2019/1/7 16:03
 */
public interface TranscationRepository extends Neo4jRepository<Transaction,Long> {

    Iterable<Transaction> findByStart_Name(String startName, @Depth int depth);

    @Query("MATCH (r:{0}) DETACH DELETE r")
    Result deleteLabel(String label);

    @Query("LOAD CSV WITH HEADERS FROM {0} AS row " +
            "CREATE (n:Product) SET n = row, " +
            "n.unitPrice = toFloat(row.unitPrice), " +
            "n.unitsInStock = toInteger(row.unitsInStock), " +
            "n.unitsOnOrder = toInteger(row.unitsOnOrder), " +
            "n.reorderLevel = toInteger(row.reorderLevel), n.discontinued = (row.discontinued <> 0)")
    Result loadTest(String url);

    @Query("LOAD CSV WITH HEADERS FROM {0} AS row " +
            "CREATE (n:{1}) SET n = row, " +
            "n.amt = toFloat(row.amt), " +
            "n.tradeTime = toInt(row.tradeTime)")
    Result loadTranscation(String url, String label);

}
